services:


  database:
    image: shop100/database
    build:
      context: ./database
      dockerfile: Dockerfile
    container_name: shop100-database
#    command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8 --collation-server=utf8_general_ci
    networks:
      - shop100-network
    ports:
      - 3306:3306
    restart: always
    volumes:
      - datavolume:/var/lib/mysql
      - /tmp/shop100/mysqld:/var/run/mysqld
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://localhost:3306" ]
      interval: 30s
      timeout: 10s
      retries: 5

  backend:
    image: shop100/backend
#    command: python manage.py runserver 0.0.0.0:8000
    command:  >
      sh -c "python manage.py makemigrations &&
            python manage.py migrate &&
            python manage.py loaddata data.json &&
            python manage.py runserver 0.0.0.0:8000"
    build:
      context: ./backend
      dockerfile: Dockerfile
#    entrypoint: ./entrypoint.sh
    container_name: shop100-backend
    networks:
      - shop100-network
    ports:
      - 8000:8000
    volumes:
      - backendvolume:/backend
      - /tmp/shop100/mysqld:/run/mysqld
    depends_on:
      database:
        condition: service_healthy
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://localhost:8000" ]
      interval: 30s
      timeout: 10s
      retries: 5


  frontend:
    image: shop100/frontend
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: shop100-frontend
    networks:
      - shop100-network
    ports:
      - 3000:3000
    environment:
      - APP_SERVICE_NAME=shop100-frontend

networks:
  shop100-network:


volumes:
  datavolume:
  backendvolume: